package cn.mrlong.usbcamera.view;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import org.greenrobot.eventbus.EventBus;

public class UsbReceiver extends BroadcastReceiver {
    public static final String closeLive = "cn.mrlong.usbcamera.view.closelive";
    public static final String openlive = "cn.mrlong.usbcamera.view.openlive";
    private static final String ACC_OFF = "android.intent.action.EXTERNAL_POWER_REMOVED";//正常熄火标志

    @Override
    public void onReceive(Context context, Intent intent) {
        if (closeLive.equals(intent.getAction())) {
            EventBus.getDefault().post(new EventMsg(closeLive));
        } else if (openlive.equals(intent.getAction())) {
            String rtmp_url = intent.getExtras().getString("rtmp_url");
            Intent toHostActivity = new Intent();
            toHostActivity.putExtra("rtmp_url",rtmp_url);
            toHostActivity.setClass(context, USBCameraActivity.class);
            toHostActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(toHostActivity);
        }else if (ACC_OFF.equals(intent.getAction())){
            EventBus.getDefault().post(new EventMsg(closeLive));
        }
    }
}